package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;

import android.graphics.Bitmap;
import android.widget.Toast;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.core.graphics.DWGraphics;
import com.handinfo.android.core.resource.Resource;
import com.handinfo.android.game.Attribute;
import com.handinfo.android.game.Cell;
import com.handinfo.android.game.GameMessage;
import com.handinfo.android.game.IIcon;
import com.handinfo.android.game.IconManger;
import com.handinfo.android.game.Role;
import com.handinfo.android.game.item.Tianming;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlTools;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWExternalDraw;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWAnimationBox;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWGrid;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWTabControl;
import com.handinfo.android.uicontrols.controls.DWTabPage;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

/**
 * 
 * @author Xiaoyingying
 * 人物属性窗口
 * 
 */
public class UIRoleStatsWindow implements IUIWindows
{
	private final String[] m_rolestats_Lable1 = {
			"名称：",
			"VIP等级：",
			"性别：",
			"家族：",
			"精力值：",
			"精魂值：",
			"荣誉点数：",
			"当前经验：",
			"双倍经验：" };

	private final String[] m_rolestats_Lable2 = {
			"等级：",
			"职业：",
			"门派：",
			"配偶：",
			"修为值：",
			"家族贡献：",
			"战功点数：",
			"下级经验：" };

	public String m_social_str = null;
	public final byte ROLE_STATE_OWN = 0;
	public final byte ROLE_STATE_OTHER = 1;

	private byte m_role_state = 0;

	public static final String[] ROLE_FACTION_LIST = { "任意", "灵隐", "天机" };
	private Role m_role = null;
	private Object[] m_bag_cell_equip;// 装备栏
	private final int[] m_role_equip_index = { 0, 10, 11, 5, 6, 7, 1, 3, 4, 12, 2, 13, 8, 9 };//武器在装备栏中索引

	private Bitmap EQUIPBACKGROUND;
	private Bitmap BUTTONIMG;
	private Bitmap ANXIAIMG;
	private Bitmap CLOSEWINDOW;// 关闭窗口图标
	private Bitmap tabSelectImg;// 选项卡选中的图标
	private Bitmap tabUnSelectImg;// 先选卡未被选中的图标
	private Bitmap titleImg;
	private Bitmap equipBoximg;
	private Bitmap equipLockImg;
	private Bitmap[] cell_equip = new Bitmap[m_role_equip_index.length];
	private Bitmap medicament;//药瓶背景

	private String[] PAGENAME = { "基础", "战斗" };

	private DWFrame m_rolestats_Frame; //人物属性主窗口
	private DWTitle m_rolestats_title;
	private DWBackground m_rolestats_leftbackground;
	private DWBackground m_rolestats_rightbackground;
	private DWGrid[] m_rolestats_equipimg = new DWGrid[m_role_equip_index.length];
	private DWGrid m_RoleStats_medicament;
	private DWAnimationBox m_rolestats_role;
	private DWTabControl m_rolestats_Control;
	private DWTabPage[] m_rolestats_Pages = new DWTabPage[2];
	private DWButton m_rolestats_statsButton;
	private DWButton m_rolestats_bagButton;
	private DWImageBox m_rolestats_close;
	private DWTextbox m_rolestats_message[] = new DWTextbox[PAGENAME.length];
	private DWImageBox m_rolestats_zhanli;
	private Bitmap m_rolestats_zhanliimg;
	private Bitmap m_rolestats_shuzi;

	private void initDate()
	{
		switch (m_role_state) {
			case ROLE_STATE_OWN:
				if (DWGameManager.getInstance().m_role != null)
				{
					m_role = DWGameManager.getInstance().m_role;
					m_bag_cell_equip = DWGameManager.getInstance().m_role.m_column_equip;
				}
				break;
			case ROLE_STATE_OTHER:
				break;
		}

	}

	private boolean m_select_equip = true;

	private void initFrame()
	{
		initDate();

		m_rolestats_Frame = new DWFrame(DWFrame.FRAME_TYPE_FULL);
		m_rolestats_Frame.setClickClose(false);

		m_rolestats_title = new DWTitle("人物属性", m_rolestats_Frame);
		m_rolestats_title.setBackground(titleImg, false);
		m_rolestats_Frame.addControl(m_rolestats_title);

		m_rolestats_close = new DWImageBox(CLOSEWINDOW);
		m_rolestats_close.setNearAnchor(m_rolestats_title, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_rolestats_close.setTouchZoomIn(UIFixWindow.TOUCHZOOM, UIFixWindow.TOUCHZOOM);
		m_rolestats_close.addListener(new DWListener() {
			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				close((byte) 0);
			}
		});
		m_rolestats_Frame.addControl(m_rolestats_close);

		m_rolestats_leftbackground = new DWBackground((m_rolestats_Frame.getShowWidth() - 80) / 2,
				m_rolestats_Frame.getShowHeight() - 55 - BUTTONIMG.getHeight());
		m_rolestats_leftbackground.setNearAnchor(m_rolestats_Frame, Tools.RIGHT_VCENTER,
				Tools.HCENTER_VCENTER, -10, -BUTTONIMG.getHeight() / 4);
		m_rolestats_Frame.addControl(m_rolestats_leftbackground);

		if (m_role != null)
		{
			m_rolestats_role = new DWAnimationBox(m_role);
			m_rolestats_role.setNearAnchor(m_rolestats_leftbackground, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
			m_rolestats_Frame.addControl(m_rolestats_role);
		}

		int moveX = (m_rolestats_leftbackground.getShowWidth() - EQUIPBACKGROUND.getWidth() * 5 - 20) / 4;

		int moveY = (m_rolestats_leftbackground.getShowHeight() - EQUIPBACKGROUND.getHeight() * 4 - 40) / 3;
		for (int i = 0; i < m_role_equip_index.length; i++) {
			m_rolestats_equipimg[i] = new DWGrid(EQUIPBACKGROUND);
			m_rolestats_equipimg[i].setDarg(true);
			switch (i) {
				case 0:
					m_rolestats_equipimg[i].setNearAnchor(m_rolestats_leftbackground, Tools.LEFT_TOP, Tools.LEFT_TOP,
							10, 20);
					break;
				case 5:
					m_rolestats_equipimg[i].setNearAnchor(m_rolestats_leftbackground, Tools.LEFT_BOTTOM,
							Tools.LEFT_BOTTOM, 10, -20);
					break;
				case 1:
				case 2:
				case 3:
				case 4:
				case 6:
				case 7:
				case 8:
				case 9:
					m_rolestats_equipimg[i].setNearAnchor(m_rolestats_equipimg[i - 1], Tools.LEFT_VCENTER,
							Tools.RIGHT_VCENTER, moveX, 0);
					break;
				case 10:
					m_rolestats_equipimg[i].setNearAnchor(m_rolestats_equipimg[0], Tools.HCENTER_TOP,
							Tools.HCENTER_BOTTOM, 0, moveY);
					break;
				case 11:
					m_rolestats_equipimg[i].setNearAnchor(m_rolestats_equipimg[5], Tools.HCENTER_BOTTOM,
							Tools.HCENTER_TOP, 0, -moveY);
					break;
				case 12:
					m_rolestats_equipimg[i].setNearAnchor(m_rolestats_equipimg[4], Tools.HCENTER_TOP,
							Tools.HCENTER_BOTTOM, 0, moveY);
					break;
				case 13:
					m_rolestats_equipimg[i].setNearAnchor(m_rolestats_equipimg[9], Tools.HCENTER_BOTTOM,
							Tools.HCENTER_TOP, 0, -moveY);
					break;
			}

			m_rolestats_Frame.addControl(m_rolestats_equipimg[i]);
		}

		setRoleImg();

		if (m_role_state == ROLE_STATE_OWN)
		{
			m_RoleStats_medicament = new DWGrid(medicament);
			m_RoleStats_medicament.addObject((Cell) DWGameManager.getInstance().m_role
					.getShortcutObject(Role.SHORTCUT_CONSUME));
			m_RoleStats_medicament.setNearAnchor(m_rolestats_equipimg[11], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 5,
					0);
			m_rolestats_Frame.addControl(m_RoleStats_medicament);

			m_rolestats_statsButton = new DWButton("背包", BUTTONIMG);
			m_rolestats_statsButton.setDownImage(ANXIAIMG);
			m_rolestats_statsButton.setNearAnchor(m_rolestats_leftbackground, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 10, 5);
			m_rolestats_statsButton.addListener(new DWListener() {
				public void OnDoubleClick()
				{
				}

				public void OnClick()
				{
					close((byte) 0);
					UIWindows.getInstance().m_bag.open(UIBag.BAG_STATE_NORMAL);
				}
			});
			m_rolestats_Frame.addControl(m_rolestats_statsButton);

			m_rolestats_bagButton = new DWButton("仓库", BUTTONIMG);
			m_rolestats_bagButton.setDownImage(ANXIAIMG);
			m_rolestats_bagButton.addListener(new DWListener() {

				public void OnDoubleClick()
				{
				}

				public void OnClick()
				{
					close((byte) 0);
					DWGameManager.getInstance().getSendMessage().sendScenePathfinding("lxd_cangku_1");
				}
			});
			m_rolestats_bagButton.setNearAnchor(m_rolestats_leftbackground, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0,
					5);
			m_rolestats_Frame.addControl(m_rolestats_bagButton);
		}
		else if (m_role_state == ROLE_STATE_OTHER)
		{
			m_rolestats_statsButton = new DWButton("天命", BUTTONIMG);
			m_rolestats_statsButton.setDownImage(ANXIAIMG);
			m_rolestats_statsButton.setNearAnchor(m_rolestats_leftbackground, Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 10, 5);
			m_rolestats_statsButton.addListener(new DWListener() {
				public void OnDoubleClick()
				{
				}

				public void OnClick()
				{
					if (m_select_equip)
					{
						m_select_equip = false;
						changLeft();
					}

				}
			});
			m_rolestats_Frame.addControl(m_rolestats_statsButton);

			m_rolestats_bagButton = new DWButton("装备", BUTTONIMG);
			m_rolestats_bagButton.setDownImage(ANXIAIMG);
			m_rolestats_bagButton.addListener(new DWListener() {

				public void OnDoubleClick()
				{
				}

				public void OnClick()
				{
					if (!m_select_equip)
					{
						m_select_equip = true;
						changLeft();
					}
				}
			});
			m_rolestats_bagButton.setNearAnchor(m_rolestats_leftbackground, Tools.HCENTER_TOP, Tools.HCENTER_BOTTOM, 0,
					5);
			m_rolestats_Frame.addControl(m_rolestats_bagButton);
		}

		m_rolestats_rightbackground = new DWBackground((m_rolestats_Frame.getShowWidth() - 80) / 2,
				m_rolestats_Frame.getShowHeight() - 60 - tabUnSelectImg.getHeight() - 5 - BUTTONIMG.getHeight());
		m_rolestats_rightbackground.setNearAnchor(m_rolestats_leftbackground, Tools.LEFT_BOTTOM,
				Tools.RIGHT_BOTTOM, 10, 0);
		m_rolestats_Frame.addControl(m_rolestats_rightbackground);

		m_rolestats_Control = new DWTabControl(tabUnSelectImg, tabSelectImg,
				m_rolestats_rightbackground.getShowWidth() - 20,
				m_rolestats_rightbackground.getShowHeight() + tabUnSelectImg.getHeight() - 20);
		m_rolestats_Control.setNearAnchor(m_rolestats_rightbackground, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, -tabUnSelectImg.getHeight());
		m_rolestats_Frame.addControl(m_rolestats_Control);

		String m_msg = getBaseMessage();

		m_rolestats_Pages[0] = new DWTabPage();
		m_rolestats_Pages[0].setName(PAGENAME[0]);

		
		m_rolestats_message[0] = new DWTextbox(m_msg, m_rolestats_Control.getShowWidth() - 40, m_rolestats_Control
				.getShowHeight() - 20 - tabUnSelectImg.getHeight());
		m_rolestats_message[0].setNearAnchor(m_rolestats_Pages[0], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
		m_rolestats_Pages[0].addControls(m_rolestats_message[0]);

		m_rolestats_Pages[1] = new DWTabPage();
		m_rolestats_Pages[1].setName(PAGENAME[1]);
		
		
		
		m_rolestats_zhanli = new DWImageBox(m_rolestats_zhanliimg);
		m_rolestats_zhanli.setNearAnchor(m_rolestats_Pages[1], Tools.LEFT_TOP, Tools.LEFT_TOP,20,10);
		DWImageBox m_shuzi = new DWImageBox(100,25);
		m_shuzi.setNearAnchor(m_rolestats_zhanli, Tools.LEFT_TOP, Tools.LEFT_BOTTOM,0,0);
		m_shuzi.addExternalDraw(new DWExternalDraw() {
			public void externalDraw(DWGraphics g, int x, int y) {
				
					Tools.drawNumber(g, m_rolestats_shuzi, x, y, m_rolestats_shuzi.getWidth()/10,
							m_rolestats_shuzi.getHeight(), 1, 1,m_role.m_zhanli, 1, Tools.LEFT_TOP, false);
	
			}
		});
		
		m_rolestats_message[1] = new DWTextbox(getZhandouMessage(), m_rolestats_Control.getShowWidth() - 40,
				m_rolestats_Control.getShowHeight() - 75 - tabUnSelectImg.getHeight());
//		Tools.debugPrintln("进入人物属性"+getZhandouMessage());
//		m_rolestats_message[1].setNearAnchor(m_rolestats_Pages[1], Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);
		m_rolestats_message[1].setNearAnchor(m_shuzi, Tools.LEFT_TOP, Tools.LEFT_BOTTOM);
		
		m_rolestats_Pages[1].addControls(m_rolestats_zhanli);
		m_rolestats_Pages[1].addControls(m_shuzi);
		m_rolestats_Pages[1].addControls(m_rolestats_message[1]);

		m_rolestats_Control.addTabPages(m_rolestats_Pages);

	}

	/**
	 * 在天命和装备界面之间切换
	 */
	private void changLeft()
	{
		removeLeft();
		if (m_select_equip) //添加装备
		{
			for (DWGrid grid : m_rolestats_equipimg) {
				m_rolestats_Frame.addControl(grid);
			}
			m_rolestats_Frame.addControl(m_rolestats_role);
		}
		else //添加天命
		{
			addTianming();
		}
	}

	/**
	 * 移除左边的控件
	 */
	private void removeLeft()
	{
		if (m_select_equip) //移除天命
		{
			for (DWGrid grid : m_tianming) {
				m_rolestats_Frame.removeControl(grid);
			}

		}
		else //移除装备
		{
			for (DWGrid grid : m_rolestats_equipimg) {
				m_rolestats_Frame.removeControl(grid);
			}
			m_rolestats_Frame.removeControl(m_rolestats_role);
		}
	}

	private DWGrid[] m_tianming;
	private static final byte TIANMINGLENGTH = 8;

	/**
	 * 添加天命
	 */
	private void addTianming()
	{
		if (m_tianming == null)
		{
			m_tianming = new DWGrid[TIANMINGLENGTH];
			//装备位背景
			for (int i = 0; i < TIANMINGLENGTH; i++) {
				if (i < m_tianming_Num) {
					m_tianming[i] = new DWGrid(equipBoximg);//已开启
					m_tianming[i].setDarg(true);
				}
				else
				{
					m_tianming[i] = new DWGrid(equipLockImg);//未开启
				}
			}

			if (tianmingbag != null)
			{
				for (int i = 0; i < tianmingbag.length; i++)
				{
					if (m_tianming[i] != null) {
						final Tianming tianming = tianmingbag[i];
						m_tianming[i].m_data = tianming;
						m_tianming[i].addListener(new DWListener() {

							public void OnDoubleClick()
							{

							}

							public void OnClick()
							{
								if (tianming != null) {
									tanchuang_XS(tianming);
									m_tcGrid_XS.m_data = tianming;
								}
							}
						});
					}
				}
			}
			m_tianming[0].setNearAnchor(m_rolestats_leftbackground, Tools.LEFT_TOP, Tools.LEFT_TOP, 20, 30 + equipBoximg.getHeight());
			m_tianming[1].setNearAnchor(m_tianming[0], Tools.LEFT_BOTTOM, Tools.RIGHT_TOP, 6, -6);
			m_tianming[2].setNearAnchor(m_tianming[1], Tools.LEFT_TOP, Tools.RIGHT_TOP, 6, 0);
			m_tianming[3].setNearAnchor(m_tianming[2], Tools.LEFT_TOP, Tools.RIGHT_BOTTOM, 6, 6);
			m_tianming[4].setNearAnchor(m_tianming[3], Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 6);
			m_tianming[5].setNearAnchor(m_tianming[4], Tools.RIGHT_TOP, Tools.LEFT_BOTTOM, -6, 6);
			m_tianming[6].setNearAnchor(m_tianming[5], Tools.RIGHT_TOP, Tools.LEFT_TOP, -6, 0);
			m_tianming[7].setNearAnchor(m_tianming[0], Tools.LEFT_TOP, Tools.LEFT_BOTTOM, 0, 6);
		}

		for (DWGrid grid : m_tianming) {
			m_rolestats_Frame.addControl(grid);
		}
	}

	public void init()
	{
		EQUIPBACKGROUND = UIWindows.createImage("/img/newui/wupinlan.gnp");
		BUTTONIMG = UIWindows.createImage("/img/newui/anniu_1.gnp");
		ANXIAIMG = UIWindows.createImage("/img/newui/anniu_1ax.gnp");
		CLOSEWINDOW = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");// 关闭窗口图标
		tabSelectImg = UIWindows.createImage("/img/newui/biaoqianye_2.gnp");
		tabUnSelectImg = UIWindows.createImage("/img/newui/biaoqianye_1.gnp");
		titleImg = UIWindows.createImage("/img/newui/renwushuxing_1.gnp");
		equipBoximg = UIWindows.createImage("/img/newui/wupinlan.gnp");// 背包物品背景
		equipLockImg = UIWindows.createImage("/img/newui/beibaost_1.gnp");//网格锁
		medicament = UIWindows.createImage("/img/newui/xuepingdi_1.gnp");
		
		m_rolestats_shuzi = UIWindows.createImage("/img/newui/shuzi_7.gnp");
		m_rolestats_zhanliimg = UIWindows.createImage("/img/newui/zhanlizhishu_1.gnp");

		for (int i = 0; i < cell_equip.length; i++)
		{
			cell_equip[i] = UIWindows.createImage("/img/newui/cell_equip_" + i + ".gnp");
		}
	}

	public void open(byte index)
	{
		m_role_state = index;
		initFrame();
		DWControlsManager.getInstance().addControl(m_rolestats_Frame);
	}

	public void close(byte index)
	{
		DWControlsManager.getInstance().removeControl(m_rolestats_Frame);
		if (mUserResource != null) {
			mUserResource.clean();
		}
		m_role = null;
		m_rolestats_Frame = null;
	}

	public void dispose()
	{
		m_rolestats_Frame = null;
	}

	/**
	 * 设置人物装备图片
	 */

	private int selectIndex = -1;

	private void setRoleImg()
	{
		if (m_bag_cell_equip != null)
		{
			for (int i = 0; i < m_role_equip_index.length; i++)
			{
				m_rolestats_equipimg[m_role_equip_index[i]].setImage(cell_equip[i]);
			}

			for (int i = 0; i < m_bag_cell_equip.length; i++)
			{

				if (m_role_state == ROLE_STATE_OWN)
				{
//					if (m_bag_cell_equip[i] == null)
//						continue;

					if (i == m_role_equip_index.length)
						break;

					final int num = m_role_equip_index[((Cell) m_bag_cell_equip[i]).m_index];
					m_rolestats_equipimg[num].addObject(m_bag_cell_equip[i]);
					if (((Cell) m_bag_cell_equip[i]).m_item != null)
						m_rolestats_equipimg[num].setImage(equipBoximg);

					m_rolestats_equipimg[num].addListener(new DWListener() {
						public void OnDoubleClick()
						{
						}

						public void OnClick()
						{
							if (selectIndex > -1)
							{
								m_rolestats_equipimg[selectIndex].setSelect(false);
							}
							selectIndex = num;
							m_rolestats_equipimg[num].setSelect(true);

							if ((Cell) m_rolestats_equipimg[num].m_data != null)
							{
								UIWindows.getInstance().m_bag
										.showItemMessage(((Cell) m_rolestats_equipimg[num].m_data).m_item);
							}
						}
					});
				}
				else if (m_role_state == ROLE_STATE_OTHER)
				{
					if (m_bag_cell_equip[i] != null)
					{
						final int num = m_role_equip_index[((SimpleItem) m_bag_cell_equip[i]).m_index];

						m_rolestats_equipimg[num].setImage(equipBoximg);
						m_rolestats_equipimg[num].addObject((SimpleItem) m_bag_cell_equip[i]);
						m_rolestats_equipimg[num].addListener(new DWListener() {
							public void OnDoubleClick()
							{
							}

							public void OnClick()
							{
								if (selectIndex > -1)
								{
									m_rolestats_equipimg[selectIndex].setSelect(false);
								}
								selectIndex = num;
								m_rolestats_equipimg[num].setSelect(true);

								DWGameManager.getInstance().getSendMessage().sendSeeItemInfos(
										((SimpleItem) m_rolestats_equipimg[num].m_data).m_guid,
										((SimpleItem) m_rolestats_equipimg[num].m_data).m_key);
							}
						});
					}

				}
			}
		}

	}

	/**
	 * 获取人物基本信息
	 * @return
	 */
	private String getBaseMessage()
	{
		String msg = "";

		msg = m_rolestats_Lable1[0] + m_role.m_name + "`"; //名称
		msg += m_rolestats_Lable2[0] + m_role.m_lv + "`"; //等级：
		msg += m_rolestats_Lable1[1] + m_role.m_vip_lv + "`"; //VIP等级
		msg += m_rolestats_Lable2[1] + Role.ROLE_VOCATION_LIST[m_role.m_vocation] + "`"; //职业
		msg += m_rolestats_Lable1[2] + Role.ROLE_SEX_LIST[m_role.m_sex] + "`";//性别
		msg += m_rolestats_Lable2[2] + ROLE_FACTION_LIST[m_role.m_faction] + "`";//门派
		msg += m_rolestats_Lable1[3] + m_role.m_family_name + "`";//家族
		msg += m_rolestats_Lable2[3] + (m_role.m_spouseName.equals("") ? "暂无配偶" : m_role.m_spouseName) + "`";//配偶
		msg += (m_role.m_shitu_guanxi.equals("")?"":m_role.m_shitu_guanxi+"`");
		if (m_role_state == ROLE_STATE_OWN)
		{
			msg += m_rolestats_Lable1[4] + m_role.m_jinglizhi_shengyu + "/" + m_role.m_jinglizhi_zonggong + "`"; //精力值
			msg += m_rolestats_Lable2[4] + m_role.m_xiuwei + "`";//修为值
			msg += m_rolestats_Lable1[5] + m_role.m_jinghun + "`"; //精魂值
			msg += m_rolestats_Lable2[5] + m_role.m_banggong + "`"; //家族贡献
			msg += m_rolestats_Lable1[6] + m_role.m_rongyu + "`";//荣誉点数
			msg += m_rolestats_Lable2[6] + m_role.m_zhangong + "`"; //战功点数
			msg += m_rolestats_Lable1[7] + m_role.m_exp + "`";//当前经验
			msg += m_rolestats_Lable2[7] + m_role.m_maxExp + "`";//下级经验
			msg += m_rolestats_Lable1[8] + "0时0分0秒";//双倍经验：	
		}

		return msg;
	}

	/**
	 * 获取人物战斗信息
	 * @return
	 */

	private String getZhandouMessage()
	{
		int[] m_attributes = m_role.m_attributes;
		String msg = "";
		for (int i = 0; i < m_attributes.length; i++)
		{
			msg += Attribute.ATTRIBUTE_NAME[i] + "：" + m_attributes[i] + "`";
			if (i > Attribute.MAX_MP && i < Attribute.SPEED)
			{
				switch (i) {
					case Attribute.力:
						msg += "<mark c=FFBB11>提升物理伤害与物理防御约" + (m_attributes[i] * 100 / 239) + "%</mark>`";
						break;
					case Attribute.智:
						msg += "<mark c=FFBB11>提升法术伤害与法术防御约" + (m_attributes[i] * 100 / 239) + "%</mark>`";
						break;
					case Attribute.技:
						msg += "<mark c=FFBB11>提升暴击值与命中约" + (m_attributes[i] * 100 / 239) + "%</mark>`";
						break;
					case Attribute.敏:
						msg += "<mark c=FFBB11>提升暴击抵抗与回避值约" + (m_attributes[i] * 100 / 239) + "%</mark>`";
						break;
				}
			}
		}
		return msg;
	}

	public void logic()
	{

	}

	class SimpleItem implements IIcon
	{
		public Bitmap m_icon;
		public Bitmap m_pinzhi;

		public long m_guid = 0;//道具唯一id
		public String m_key;//道具key
		public int m_iconId;//icon
		public int m_quality;//品质
		public int m_index; //索引

		public void recvItemFormServer(DataInputStream dis) throws IOException
		{
			m_index = dis.readByte();
			m_guid = dis.readLong();
			m_key = dis.readUTF();
			m_iconId = dis.readShort();
			m_quality = dis.readByte();
			m_icon = IconManger.getInstance().getIcon(m_iconId);
			m_pinzhi = IconManger.getInstance().getPinzhi(m_quality);
		}

		public void drawIcon(DWGraphics g, int x, int y, int w, int h, int anchor)
		{
			if (m_icon != null) {
				g.drawBitmap(m_icon, x, y, anchor);
			}
			if (m_pinzhi != null) {
				g.drawBitmap(m_pinzhi, x, y, w, h, anchor);
			}
		}

		public void drawIcon(DWGraphics g, int x, int y, int w, int h, float scaleX, float scaleY, int anchor)
		{
		}
	}

	private Resource mUserResource = new Resource();

	/**
	 * 查看其它人物信息
	 * @param dis
	 * @throws IOException
	 */
	public void recvOtherRoleInfo(DataInputStream dis) throws IOException
	{
		DWGameManager.getInstance().getSendMessage().unlockNetwork(GameMessage.锁_人物信息);

		int states = dis.readByte();

		Tools.debugPrintln("-------------------->" + states);
		switch (states)
		{
			case 1:
				m_role = new Role(mUserResource);
				m_role.m_gameId = dis.readLong();
				Tools.debugPrintln("gameId：" + m_role.m_gameId);

				String[] urls = new String[5];
				for (int i = 0; i < 5; i++) {
					urls[i] = dis.readUTF();
					Tools.debugPrintln("urls[" + i + "]" + urls[i]);
				}

				m_role.m_spouseName = dis.readUTF();
				Tools.debugPrintln("m_role.m_spouseName=" + m_role.m_spouseName);
				//天命
				m_tianming_Num = dis.readByte();//天命栏开启个数
				Tools.debugPrintln("m_tianming_Num:" + m_tianming_Num);
				byte tianmingbagNum = dis.readByte(); //天命装备个数
				Tools.debugPrintln("tianmingbagNum:" + tianmingbagNum);
				tianmingbag = null;
				tianmingbag = new Tianming[tianmingbagNum];
				for (int i = 0; i < tianmingbagNum; i++) {
					Tianming tm = new Tianming();
					tm.setLevel(dis.readByte()); //等级
					tm.setName(dis.readUTF()); //名字
					tm.setQualityType(dis.readByte());//天命品质
					tm.setPropertyType(dis.readByte()); //类型
					tm.setAddAttribute(dis.readInt()); //增加属性值
					tm.setWhileCell(dis.readByte());//装备位
					tm.currntML = dis.readInt(); //当前命力
					tm.maxML = dis.readInt(); //最大命力
					tianmingbag[i] = tm;
				}

				byte size = dis.readByte();
				m_bag_cell_equip = new SimpleItem[size];
				for (int i = 0; i < size; i++)
				{
					m_bag_cell_equip[i] = new SimpleItem();
					((SimpleItem) m_bag_cell_equip[i]).recvItemFormServer(dis);
				}

				m_role.m_name = dis.readUTF();
				Tools.debugPrintln("名字 : " + m_role.m_name);

				m_role.m_family_name = dis.readUTF();
				Tools.debugPrintln("家族名称 : " + m_role.m_family_name);

				m_role.m_sex = dis.readByte();
				Tools.debugPrintln("性别 : " + m_role.m_sex);

				m_role.m_vocation = dis.readByte();
				Tools.debugPrintln("职业 : " + m_role.m_vocation);

				m_role.m_faction = dis.readByte();
				Tools.debugPrintln("阵营 : " + m_role.m_faction);

				m_role.m_lv = dis.readInt();
				Tools.debugPrintln("等级 : " + m_role.m_lv);

				m_role.m_vip_lv = dis.readByte();
				Tools.debugPrintln("VIP等级 : " + m_role.m_vip_lv);

				m_role.m_status = dis.readByte();
				Tools.debugPrintln("状态 : " + m_role.m_status);

				m_role.m_action = dis.readInt();
				Tools.debugPrintln("行为 : " + m_role.m_action);

				m_role.m_hp = dis.readInt();
				Tools.debugPrintln("当前HP : " + m_role.m_hp);

				m_role.m_mp = dis.readInt();
				Tools.debugPrintln("当前MP : " + m_role.m_mp);

				m_role.m_exp = (int) dis.readLong();
				Tools.debugPrintln("当前经验 : " + m_role.m_exp);

				m_role.m_maxExp = (int) dis.readLong();
				Tools.debugPrintln("当前总经验 : " + m_role.m_maxExp);

				m_role.m_gold = dis.readLong();
				Tools.debugPrintln("游戏金币 : " + m_role.m_gold);

				m_role.m_zhangong = dis.readLong();
				Tools.debugPrintln("游戏战功 : " + m_role.m_zhangong);

				m_role.m_rmb = dis.readLong();
				Tools.debugPrintln("游戏元宝 : " + m_role.m_rmb);

				m_role.m_banggong = dis.readLong();
				Tools.debugPrintln("游戏帮贡 : " + m_role.m_banggong);

				m_role.m_xiuwei = dis.readLong();
				Tools.debugPrintln("游戏修为 : " + m_role.m_xiuwei);

				m_role.m_jinghun = dis.readLong();
				Tools.debugPrintln("游戏精魂 : " + m_role.m_jinghun);
				
				m_role.m_zhanli = dis.readLong();
				Tools.debugPrintln("战力指数 : " + m_role.m_zhanli);

				m_role.m_position = dis.readByte();
				Tools.debugPrintln("家族职位 : " + m_role.m_position);

				m_role.m_teamID = dis.readLong();
				Tools.debugPrintln("队伍ID : " + m_role.m_teamID);

				m_role.m_jinglizhi_zonggong = dis.readInt();
				Tools.debugPrintln("总共精力值: " + m_role.m_jinglizhi_zonggong);

				m_role.m_jinglizhi_shengyu = dis.readInt();
				Tools.debugPrintln("剩余精力值: " + m_role.m_jinglizhi_shengyu);

				//其他属性
				int attributes_size = dis.readByte();
				m_role.m_attributes = new int[attributes_size];
				for (int i = 0; i < attributes_size; i++) {
					m_role.m_attributes[i] = dis.readInt();
				}

				m_role.m_shitu_guanxi = dis.readUTF();

				m_role.m_hpMax = m_role.getAttr(Attribute.MAX_HP);
				Tools.debugPrintln("当前HP_MAX: " + m_role.m_hp);

				m_role.m_mpMax = m_role.getAttr(Attribute.MAX_MP);
				Tools.debugPrintln("当前MP_MAX: " + m_role.m_mp);

				m_role.initRoleAnims(mUserResource, urls);
				m_tianming = null;
				m_select_equip = true;

				if (DWControlsManager.getInstance().contains(UIWindows.getInstance().m_social.m_si_fram)
						&& UIWindows.getInstance().m_social.m_isLook == true) {
					m_social_str = m_role.m_name + "," + m_role.m_lv + "," + m_role.m_vip_lv + "," + m_role.m_vocation
							+ "," + m_role.m_sex + "," + m_role.m_faction + "," + m_role.m_family_name + ","
							+ m_role.m_spouseName+","+m_role.m_shitu_guanxi;
					UIWindows.getInstance().m_social.refreshRightList(m_social_str);
					return;
				}

				open(ROLE_STATE_OTHER);
				break;
			case 2:
				DWGameManager.getInstance().showToast("角色不在线~", Toast.LENGTH_SHORT);
				break;
			default:
				DWGameManager.getInstance().showToast("查看失败~", Toast.LENGTH_SHORT);
				break;
		}
	}

	private byte m_tianming_Num; //天命缓存栏天命个数
	private Tianming[] tianmingbag;

	/**
	 * 天命属性显示界面
	 */
	public DWFrame m_tcFrame_XS = null;
	public DWTitle m_tcTitle_XS = null;
	public DWImageBox m_tcImageBox_XS = null;
	public DWBackground m_tcBackground_XS = null;
	public DWTextbox m_tcTextbox_XS01 = null;//天命阶
	public DWTextbox m_tcTextbox_XS02 = null;//命力
	public DWTextbox m_tcTextbox_XS03 = null;//天命类型
	public DWGrid m_tcGrid_XS = null;

	public void tanchuang_XS(final Tianming tianming)
	{
		m_tcFrame_XS = new DWFrame(DWGameManager.Screen_Width / 2, DWGameManager.Screen_Height / 2 + 60);
		m_tcFrame_XS.setNearAnchor(m_rolestats_Frame, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER);

		m_tcTitle_XS = new DWTitle("选项", m_tcFrame_XS);

		//关闭按钮
		m_tcImageBox_XS = new DWImageBox(CLOSEWINDOW);
		m_tcImageBox_XS.setTouchZoomIn(UIFixWindow.TOUCHZOOM, UIFixWindow.TOUCHZOOM);
		m_tcImageBox_XS.addListener(new DWListener() {

			public void OnDoubleClick()
			{
			}

			public void OnClick()
			{
				DWControlsManager.getInstance().removeControl(m_tcFrame_XS);
			}
		});
		m_tcImageBox_XS.setNearAnchor(m_tcTitle_XS, Tools.RIGHT_VCENTER, Tools.RIGHT_VCENTER);
		m_tcImageBox_XS.setTouchZoomIn(20, 20);

		m_tcBackground_XS = new DWBackground(m_tcFrame_XS.getShowWidth() - 20, m_tcFrame_XS.getShowHeight() - 30);
		m_tcBackground_XS.setNearAnchor(m_tcTitle_XS, Tools.HCENTER_TOP, Tools.HCENTER_TOP, 0, 40);

		m_tcGrid_XS = new DWGrid(equipBoximg);
		m_tcGrid_XS.setNearAnchor(m_tcBackground_XS, Tools.LEFT_TOP, Tools.LEFT_TOP, 30, 30);

		m_tcTextbox_XS01 = new DWTextbox(Tianming.getTianmingLevel(tianming.getQualityType())
				+ DWControlTools.CHANGE_ROW
				+ "级别："
				+ tianming.getLevel()
				+ "级", 170, 100);

		m_tcTextbox_XS03 = new DWTextbox("<mark c="
				+ Tianming.getTianmingColor(tianming.getQualityType())
				+ ">"
				+ tianming.getName()
				+ "</mark>");

		m_tcTextbox_XS02 = new DWTextbox("增加“"
				+ Tianming.getTianMType(tianming.getPropertyType())
				+ "”"
				+ tianming.getAddAttribute()
				+ "点"
				+ DWControlTools.CHANGE_ROW
				+ "命力:"
				+ tianming.currntML
				+ "/"
				+ tianming.maxML,  m_tcFrame_XS.getShowWidth() - 100, 100);

		m_tcTextbox_XS01.setNearAnchor(m_tcBackground_XS, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 20);
		m_tcTextbox_XS02.setNearAnchor(m_tcBackground_XS, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 35);
		m_tcTextbox_XS03.setNearAnchor(m_tcGrid_XS, Tools.LEFT_TOP, Tools.RIGHT_TOP, 10, 10);

		m_tcFrame_XS.addControl(m_tcBackground_XS);
		m_tcFrame_XS.addControl(m_tcTitle_XS);
		m_tcFrame_XS.addControl(m_tcImageBox_XS);
		m_tcFrame_XS.addControl(m_tcGrid_XS);
		m_tcFrame_XS.addControl(m_tcTextbox_XS01);
		m_tcFrame_XS.addControl(m_tcTextbox_XS02);
		m_tcFrame_XS.addControl(m_tcTextbox_XS03);
		DWControlsManager.getInstance().addControl(m_tcFrame_XS);
	}

}
